package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺营业控制器")
public class ShopController {
    @Resource
    private RedisTemplate redisTemplate;
    private final String SHOP_STATUS = "SHOP_STATUS";

    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result<String> setStatus(@PathVariable Integer status) {
        log.info("[设置营业状态] status:{}", status);
        //操作redis String
        redisTemplate.opsForValue().set(SHOP_STATUS, status);
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getStatus() {
        //读取redis
        Object status = redisTemplate.opsForValue().get(SHOP_STATUS);
        //打烊 0 营业 1
        return status!=null?Result.success((Integer) status):Result.success(0);

    }

}
